home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10906 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: Mike Girou <girou@parashift.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: NEWBIE: Returning 0 as refernce
  5. Date: Sun, 10 Mar 1996 19:02:04 -0600
  6. Organization: Paradigm Shift, Inc.
  7. Message-ID: <31437B8C.3400@parashift.com>
  8. References: <4huslk$rpk@badger.wmin.ac.uk> <4hvglg$v4@news4.digex.net>
  9. NNTP-Posting-Host: ix-dfw18-10.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NETCOM-Date: Sun Mar 10  5:02:30 PM PST 1996
  14. X-Mailer: Mozilla 2.0 (Win95; I)
  15.  
  16. > Renato Araujo (tqaec@westminster.ac.uk) wrote:
  17. > : I am trying to write bits of Linux in C++. In order to make it fast I try to
  18. > : return references instead of pointers (some classes are rather big). But what
  19. > : is the standard way of returning a reference when it is not found
  20.  
  21. If the referent is supposed to exist, you might throw an exception
  22. for the rare cases when it isn't there.  If the referent may or may
  23. not exist, then return a pointer, which can be NULL.  You will not
  24. get any performance improvements with references versus pointers.
  25. You should generally use references if you can, pointers if you have
  26. to.  References, particular if const, are a valuable way to document
  27. your assumptions and protect against unintended modifications later.
  28.  
  29. Mike
  30.  
  31. -- 
  32. Mike Girou              girou@parashift.com
  33.